<script setup>
import { ref, reactive, onMounted } from "vue";
import { getConfigsList, editConfigslnfo, editConfigs } from "@/api/system";
import Editor from "@/components/Editor/index.vue";
import { ElMessage } from "element-plus";

const ruleFormRef = ref();
const formData = ref();
const loading = ref(false);

getConfigList();
async function getConfigList() {
  loading.value = true;
  const res = await getConfigsList();
  formData.value = res.data;
  loading.value = false;
}

async function save(row) {
  const res = await editConfigs(row);
  if (res.code == 200) {
    ElMessage.success("修改成功");
    await getConfigList();
  }
}
</script>

<template>
  <div class="container">
    <p class="title">系统设置</p>
    <div class="box" v-loading="loading">
      <el-form
        v-if="!loading"
        ref="ruleFormRef"
        style="width: 100%"
        :model="formData"
        label-width="auto"
        status-icon
      >
        <el-form-item v-for="(item, index) in formData" :label="item.title" required>
          <el-input
            v-if="item.types == 1"
            v-model="item.value"
            placeholder="请输入"
          ></el-input>
          <Editor v-if="item.types == 2" v-model="item.value" />
          <el-button type="primary" @click="save(item)">保存</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
